import { _decorator, BoxCollider2D, Component, Contact2DType, ERigidBody2DType, math, Node, RigidBody2D, TiledObjectGroup } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('FriendManager')
export class FriendManager extends Component {
    rigidBody2D:RigidBody2D
    boxCollider2D:BoxCollider2D
    onLoad(){
        this.rigidBody2D = this.node.addComponent(RigidBody2D)
        //分组是2的次方，项目设置的碰撞矩阵中friend的index是5，要设置节点的分组就是2^5=32
        this.rigidBody2D.group = 32
        //碰撞监听要加启动监听，不然无效
        this.rigidBody2D.enabledContactListener=true
        this.rigidBody2D.type = ERigidBody2DType.Kinematic
        this.rigidBody2D.awakeOnLoad = true

        this.boxCollider2D = this.node.addComponent(BoxCollider2D)
        this.boxCollider2D.group = 32
        this.boxCollider2D.size = math.size(100, 100)
        this.boxListener()
        
    }
    boxListener(){
        this.boxCollider2D.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
    }

    onBeginContact(){
        console.log("碰撞到了")
    }
}

